import { Component, OnInit,Output,Input,EventEmitter } from '@angular/core';
const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
import { Router } from '@angular/router';
import { NzModalRef, NzFormatEmitEvent, NzModalService, NzTreeComponent, NzTreeNodeOptions, NzMessageService } from 'ng-zorro-antd';
import { PagesService } from '../../services/pages.service';
import { UtilService } from '../../services/util.service';
import { RequestService } from '../../services/request.service';
declare var layui: any;
declare var layer: any;
declare var $: any;

@Component({
  selector: 'app-brand',
  templateUrl: './brand.component.html',
  styleUrls: ['./brand.component.scss']
})
export class BrandComponent implements OnInit {

  constructor(public router: Router, private http: HttpClient, public interfaceService: PagesService, public utilService: UtilService,public request:RequestService) {
    
  }

  @Output()  private  outer=new EventEmitter();


  ngOnInit() {
    
  }

  field1=[]     //table表格1-主表列字段集合
  data1={}      //table表格1-主表对象数据集合
  data1_dis={}  //table表格1-主表对象禁用集合
  data1_sel=[]  //table表格1-主表下拉框数据集合

  /**
   * 表格字段动态列集合生成
   * 
   */
  
  filed_tablelist(){
    this.interfaceService.postPage("/erp/common/fields/getfieldsbytype",{"type":"goods.BrandPopUpVO"}).subscribe((data: any) => {
      if (this.interfaceService.codeValidation(data)) {
      if(data.code==200){
        if(this.popup01_checkbox==1){
          this.field1=this.utilService.filed_list(data.object,1);
        }else{
          this.field1=this.utilService.filed_list(data.object);
        }
        for(var i=0;i<data.object.length;i++){
          this.data1[data.object[i]["fieldValue"]]=""
		      this.data1_dis[data.object[i]["fieldValue"]]=true
        }
      }
      this.popup01 = true;
      this.popup01_table();
    }
    });
  }

  userStatus_list=JSON.parse(localStorage.getItem("userStatus_list"))
  popup01_url='';
  popup01_id='';
  popup01_checkbox=0
  popup01 = false;
  popup01_show(url,checkbox?): void {//checkbox参数可选，默认表格双击单选，传1为表格多选
    this.popup01_url=url
    // this.popup01_id=id;
    if (checkbox == 1){
      this.popup01_checkbox=1
    }else{
      this.popup01_checkbox=0
    }
    this.filed_tablelist();//表格字段动态列集合生成

  }
  popup01_hide(): void {
    this.popup01 = false;
    this.popup01_url='';
    this.popup01_id='';
    this.popup01_ss1='';
    this.popup01_ss2='';
  }

  popup01_ss1='';
  popup01_ss2='';
  popup01_table(){
	this.popup01_listTable(this.popup01_url+"&brandId=" + this.popup01_ss1 +"&brandName=" + this.popup01_ss2);
  }

  popup01_listTable(url):void{
    setTimeout(()=>{ 
      layui.use(['table'], (obj)=>{
        var  table = layui.table
        if(this.popup01_checkbox==1){
          var tab=this.utilService.getTable(url,"#popup01_tblist_brand",this.field1)
          tab["toolbar"]='#toolbarIndex2_brand'
          tab["defaultToolbar"]=[]
          table.render(tab);
           //头工具栏事件
          table.on('toolbar(popup01_tblist_brand)', (obj)=>{
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
              case 'getCheckData':
                var data = checkStatus.data;
              if(data.length>0){
                this.popup01_hide();
                this.outer.emit(data)
              }else{
                layer.msg("请选择数据后操作！")
              }
              break;
            };
          });
        }else{
          table.render(this.utilService.getTable(url,"#popup01_tblist_brand",this.field1));
          table.on('rowDouble(popup01_tblist_brand)', (obj)=>{
            this.popup01_hide();
            this.outer.emit(obj.data)       
           });
        }
      });
    },50);
  }

}
